package retrofitdemo.com.night.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import androidx.databinding.DataBindingUtil;

import com.lzy.okgo.callback.StringCallback;

import okhttp3.Call;
import okhttp3.Response;
import retrofitdemo.com.night.R;
import retrofitdemo.com.night.databinding.ActivityRegisterBinding;
import retrofitdemo.com.night.utils.HTTPAPI;
import retrofitdemo.com.night.utils.LogUtils;

public class RegisterActivity extends BaseActivity {

    ActivityRegisterBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this,R.layout.activity_register);
        binding.setActivity(this);
        initView();
    }

    private void initView() {

        binding.btnModuleRegister.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        int sS_id = view.getId();
        if (sS_id == R.id.btnModuleRegister){
            LogUtils.e("注册");
            register();
        }
    }

    public void register(){
        String phone = binding.etModulePhone.getText().toString().trim();
        if (TextUtils.isEmpty(phone)) {
            showToast("请输入账号");
            return;
        }

        String pwd = binding.etModulePwd.getText().toString().trim();
        if (TextUtils.isEmpty(pwd)) {
            showToast("请输入密码");
            return;
        }

        String name = binding.etModuleName.getText().toString().trim();
        if (TextUtils.isEmpty(name)) {
            showToast("请输入昵称");
            return;
        }

        HTTPAPI.getInstance().register(phone,name,pwd, new StringCallback() {
            @Override
            public void onSuccess(String s, Call call, Response response) {
                LogUtils.e("注册成功-->"+ s);
                finish();
            }
        });

    }

}
